{extend name="login:layout" /}
{block name="title"}修改密码 - {$__site_name__}{/block}

{block name="body"}


<div class="layui-card">
    <div class="layui-card-header">修改密码 - {$__site_name__}</div>
    <div class="layui-card-body">


        <form class="layui-form">

            <label class="form-item">
                <i class="layui-icon layui-icon-username"></i>
                <input type="password" name="opassword" placeholder="请输入账号" autocomplete="off" class="layui-input">
            </label>

            <label class="form-item">
                <i class="layui-icon layui-icon-password"></i>
                <input type="password" name="password" placeholder="请输入密码" autocomplete="off" class="layui-input">
            </label>

            <label class="form-item">
                <i class="layui-icon layui-icon-password"></i>
                <input type="password" name="rpassword" placeholder="请再次输入密码" autocomplete="off" class="layui-input">
            </label>

            <label class="form-item form-item-verify">
                <i class="layui-icon layui-icon-auz"></i>
                <input type="text" name="code" placeholder="验证码" autocomplete="off" class="layui-input">
                <img class="verify" src="{:url('verify')}" alt="captcha"/>
            </label>


            <button lay-submit lay-filter="register" class="layui-btn layui-btn-normal">修改</button>

            <a href="{:url('login')}">返回登录</a>

        </form>


    </div>
</div>

{/block}

{block name="body_script"}
<script>
    layui.use(['jquery', 'form', 'layer'], function () {
        let form = layui.form, $ = layui.jquery, layer = layui.layer;

        // 表单提交
        form.on('submit(register)', function (data) {

            if (!data.field.opassword) {
                layer.msg('请输入账号', {icon: 2});
                $('input[name=opassword]').focus();
                return false;
            }

            if (!data.field.password) {
                layer.msg('请输入密码', {icon: 2});
                $('input[name=password]').focus();
                return false;
            }

            if (data.field.password.length < 6) {
                layer.msg('密码不能小于6位', {icon: 2});
                $('input[name=password]').focus();
                return false;
            }

            if (!data.field.rpassword) {
                layer.msg('请确认密码', {icon: 2});
                $('input[name=rpassword]').focus();
                return false;
            }

            if (data.field.password !== data.field.rpassword) {
                layer.msg('两次密码输入不一致', {icon: 2});
                $('input[name=rpassword]').focus();
                return false;
            }

            if (!data.field.code) {
                layer.msg('请输入验证码', {icon: 2});
                $('input[name=code]').focus();
                return false;
            }

            $.post('{:url("change_pwd")}', data.field, res => {
                if (res.code) {
                    layer.msg('密码修改成功', {icon: 1},function () {
                        window.location.href = res.data.url;
                    });

                } else {
                    layer.msg(res.msg, {icon: 2});
                }
            })

            return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
        });

    });
</script>
{/block}
